//package com.pengshun.modules.api.adapay.service.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.huifu.adapay.model.Drawcash;
//import com.huifu.adapay.model.Member;
//import com.huifu.adapay.model.SettleAccount;
//import com.pengshun.modules.api.adapay.service.AdaPayService;
//import com.pengshun.modules.api.adapay.service.dto.AdaPayCommon;
//import com.pengshun.modules.api.adapay.service.dto.UserAdaPayDto;
//import com.pengshun.modules.api.coal.repository.UserRepository;
//import com.pengshun.modules.api.coal.service.dto.UserDto;
//import com.pengshun.modules.common.BaseResult;
//import com.pengshun.modules.domain.User;
//import lombok.RequiredArgsConstructor;
//import org.springframework.stereotype.Service;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author luoligang
// * @create 2021/2/26
// */
//
//@Service
//@RequiredArgsConstructor
//public class AdaPayServiceImpl implements AdaPayService {
//
//    private final UserRepository userRepository;
//
//
//    @Override
//    public BaseResult addMember(Long userId) throws Exception {
//        User user=userRepository.findById(userId).orElseGet(User::new);
//        if(user==null){
//            return  new BaseResult(1,"用户不存在");
//        }
//        //判断是否创建账户
//
//        System.out.println("=======execute CreateMember begin=======");
//        Map<String, Object> memberParams = new HashMap<String, Object>(2);
//        memberParams.put("member_id", userId);
//        memberParams.put("app_id", AdaPayCommon.appId);
////        memberParams.put("location", "上海市徐汇区宜山路");
////        memberParams.put("email", "123@163.com");
////        memberParams.put("gender", "MALE");
//        memberParams.put("tel_no", user.getPhone());
//        memberParams.put("nickname", user.getName());
//        System.out.println("创建用户，请求参数：" + JSON.toJSONString(memberParams));
//        Map<String, Object> member = Member.create(memberParams);
//        System.out.println("创建用户，返回参数：" + JSON.toJSONString(member));
//        System.out.println("=======execute CreateMember end=======");
//
//
//
//        return null;
//    }
//
//    @Override
//    public String notifys(HttpServletRequest request) {
//        return null;
//    }
//
//
//    /**
//     * 创建用户对象
//     * @param app_id
//     * @param user
//     * @return
//     * @throws Exception
//     */
//    private  Map<String, Object> executeCreateMember( String app_id,User user) throws Exception {
//        System.out.println("=======execute CreateMember begin=======");
//        Map<String, Object> memberParams = new HashMap<String, Object>(2);
//        memberParams.put("member_id", user.getId());
//        memberParams.put("app_id", app_id);
////        memberParams.put("location", "上海市徐汇区宜山路");
////        memberParams.put("email", "123@163.com");
////        memberParams.put("gender", "MALE");
//        memberParams.put("tel_no", user.getPhone());
//        memberParams.put("nickname", user.getName());
//        System.out.println("创建用户，请求参数：" + JSON.toJSONString(memberParams));
//        Map<String, Object> member = Member.create(memberParams);
//        System.out.println("创建用户，返回参数：" + JSON.toJSONString(member));
//        System.out.println("=======execute CreateMember end=======");
//        return member;
//    }
//
//
//    /**
//     * 创建用户 结算对象
//     * @param app_id
//     * @param member_id
//     * @return
//     * @throws Exception
//     */
//    private Map<String, Object> executeCreateSettleAccount(String app_id, String member_id, UserAdaPayDto dto) throws Exception {
//        System.out.println("=======execute Create SettleAccount begin=======");
//        Map<String, Object> settleCountParams = new HashMap<String, Object>(2);
//        Map<String, Object> accountInfo = new HashMap<String, Object>(2);
//        //银行卡号
//        accountInfo.put("card_id", dto.getCard_id());
//        //银行卡对应的户名
//        accountInfo.put("card_name", dto.getCard_name());
//        //证件号，银行账户类型为对私时，必填
//        accountInfo.put("cert_id", dto.getCert_id());
//        //证件类型，仅支持：00-身份证，银行账户类型为对私时，必填
//        accountInfo.put("cert_type", "00");
//        //手机号
//        accountInfo.put("tel_no", dto.getTel_no());
//        // 银行编码，详见附录 银行代码
//        accountInfo.put("bank_code", dto.getBank_code());
//        //银行账户类型：1-对公；2-对私
//        accountInfo.put("bank_acct_type", "2");
//        //银行账户开户银行所在省份编码 （省市编码）
//        accountInfo.put("prov_code", dto.getProv_code());
//        //银行账户开户银行所在地区编码（省市编码）
//        accountInfo.put("area_code", dto.getArea_code());
//        settleCountParams.put("member_id", member_id);
//        settleCountParams.put("app_id", app_id);
////        目前仅支持：bank_account（银行卡）
//        settleCountParams.put("channel", "bank_account");
//        settleCountParams.put("account_info", accountInfo);
//        System.out.println("创建结算账户，请求参数：" + JSON.toJSONString(settleCountParams));
//        Map<String, Object> settleCount = SettleAccount.create(settleCountParams);
//        System.out.println("创建结算账户，返回参数：" + JSON.toJSONString(settleCount));
//        System.out.println("=======execute Create SettleAccount end=======");
//
//        return settleCount;
//
//    }
//
//    /**
//     * 取现
//     * @param app_id
//     * @param member_id
//     * @return
//     * @throws Exception
//     */
//    private static Map<String, Object> executeDrawCash(String app_id, String member_id) throws Exception {
//        System.out.println("=======execute modify SettleAccount begin=======");
//        Map<String, Object> settleCountParams = new HashMap<String, Object>();
//
//        settleCountParams.put("order_no", "jsdk_payment_" + System.currentTimeMillis());
//        //取现金额，必须大于0，人民币为元，保留两位小数点，如0.10、100.05等
//        settleCountParams.put("cash_amt", "1.00");
//        settleCountParams.put("member_id", member_id);
//        settleCountParams.put("app_id", app_id);
//        // settleCountParams.put("settle_account_id", "0008919797515968");
//        //取现类型：T1-T+1取现；D1-D+1取现；D0-即时取现。
//        settleCountParams.put("cash_type", "D0");
//        settleCountParams.put("notify_url", "");
//
//        System.out.println("取现接口，请求参数：" + JSON.toJSONString(settleCountParams));
//        Map<String, Object> settleCount = Drawcash.create(settleCountParams);
//        System.out.println("取现接口返回参数" + JSON.toJSONString(settleCount));
//        System.out.println("=======execute modify SettleAccount end=======");
//
//        return settleCount;
//    }
//}
